var login = getCookie('login')
var bdlogin = getCookie('data')
if (login) {
	$('#login').html(`<span>${login}</span>`)
	$('#regist').html(`<span>退出</span>`)
	$('#regist>span').click(function () {
		setCookie('login', 1, -180)
		location.reload()
	})
	var data = JSON.parse(localStorage.getItem('data1'))
	var x = data.reduce((pre, item) => {
		return pre + item.num * 1
	}, 0)
	$('#carr>a').html(`购物车(${x})`)
}
if (!login && bdlogin) {
	var data = JSON.parse(localStorage.getItem('data'))
	var x = data.reduce((pre, item) => {
		return pre + item.num * 1
	}, 0)
	$('#carr>a').html(`购物车(${x})`)
}
// 引入轮播图
var swiper = new Swiper('.swiper-container', {
	pagination: {
		el: '.swiper-pagination',
		clickable: true,
	},
	loop: true,
	autoplay: {
		delay: 3000,
		stopOnLastSlide: false,
		disableOnInteraction: true,
	},
	navigation: {
		nextEl: '.swiper-button-next',
		prevEl: '.swiper-button-prev',
	},
})
// 滚动事件导航栏固定
$(Window).scroll(function () {
	if ($(window).scrollTop() > 500) {
		console.log(1)
		$('.dhl').css({
			position: 'fixed',
			background: '#fff',
			top: 0,
		})
	} else {
		$('.dhl').css({
			position: 'relative',
		})
	}
})
//   动画
var x = parseInt($('#splb img').css('height'))
$('#splb a').hover(
	function () {
		$('#splb img')
			.eq($(this).index())
			.stop()
			.animate(
				{
					height: x - 5,
				},
				100
			)
	},
	function () {
		$('#splb img').eq($(this).index()).stop().animate(
			{
				height: x,
			},
			100
		)
	}
)
